#include<iostream>
#include<pcl/io/pcd_io.h>
#include<pcl/point_types.h>
#include<pcl/compression/octree_pointcloud_compression.h>
#include<pcl/console/time.h>
#include<pcl/octree/octree_search.h>
#include<pcl/visualization/cloud_viewer.h>

typedef pcl::PointXYZ pointXYZ;

int main()
{
	pcl::PointCloud<pointXYZ>::Ptr cloud(new pcl::PointCloud<pointXYZ>);//输入数据
	pcl::console::TicToc time;//运行时间
	time.tic();//开始时间
	if (pcl::io::loadPCDFile("D:\\wzs(onlyTree).pcd", *cloud) == -1)
	{
		return -1;
	}
	std::cout << "读取数据成功,用时：" << time.toc() / 1000 << "s" << std::endl;

	bool ShowStatistics = true;//是否查看压缩信息
	pcl::io::compression_Profiles_e comprfile = pcl::io::MED_RES_OFFLINE_COMPRESSION_WITHOUT_COLOR;
	pcl::io::OctreePointCloudCompression<pointXYZ>::Ptr pointCloudencoder(new pcl::io::OctreePointCloudCompression<pointXYZ>(comprfile,ShowStatistics));
	// 压缩结果stringstream
	std::stringstream compressedData;
	// 输出点云
	pcl::PointCloud<pointXYZ>::Ptr cloudOut(new pcl::PointCloud<pointXYZ>());
	// 压缩点云
	pointCloudencoder->encodePointCloud(cloud->makeShared(), compressedData);
	std::cout << compressedData.str() << std::endl;
	// 解压点云
	pointCloudencoder->decodePointCloud(compressedData, cloudOut);
	pcl::visualization::CloudViewer viewer("Simple Cloud Viewer");
	viewer.showCloud(cloudOut);
	while (!viewer.wasStopped())
	{
	}
	std::system("pause");
	return 0;
}
